<template>
  <div class="warehouse">
    <el-row class="head fff">
      <el-form
        :inline="true"
        :model="searchForm"
        label-position="top"
        class="search"
      >
        <el-col :span="6">
          <el-form-item label="损益单号">
            <el-input
              v-model="searchForm.code"
              placeholder="请输入"
            /> </el-form-item></el-col>
        <el-col :span="6">
          <el-form-item label="损益单状态">
            <el-select v-model="searchForm.status" clearable placeholder="请选择">
              <el-option
                v-for="item in status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select></el-form-item></el-col>
        <el-col :span="6">
          <el-form-item label="货主名称">
            <el-input
              v-model="searchForm.ownerName"
              placeholder="请输入"
            /> </el-form-item></el-col>
        <el-col :span="6" class="submit">
          <el-form-item>
            <el-button type="primary" @click="onSubmit">搜索</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item></el-col>
        <el-col :span="6">
          <el-form-item label="货品名称">
            <el-input
              v-model="searchForm.goodsName"
              placeholder="请输入"
            /> </el-form-item></el-col>
      </el-form>
    </el-row>
    <el-row class="table fff">
      <div v-if="isNowData" class="now-data">
        <span class="imgIcon" /><span style="color: #b5abab">暂无数据</span>
      </div>
      <template v-else>
        <div class="infoTip">总计：{{ tableData.total }}个库位 {{ sum }}个 货品</div>
        <el-table
          :data="tableData.records"
          stripe
          border
          :row-style="{}"
          :header-cell-style="{
            background: '#f9f6ee',
            borderColor: '#f5efee!important',
            padding: '10px 0',
          }"
          :cell-style="{ borderColor: '#f5efee!important', padding: '10px 0' }"
        >
          <el-table-column label="序号" width="68" align="center">
            <template v-slot="{ $index }">{{ $index + 1 }}</template>
          </el-table-column>
          <el-table-column
            prop="code"
            label="损益单号"
            align="center"
            width="160"
          />
          <el-table-column
            prop="warehouseName"
            label="仓库名称"
            align="center"
            width="160"
          />
          <el-table-column
            prop="areaName"
            label="库区名称"
            align="center"
            width="160"
          />
          <el-table-column
            prop="locationName"
            label="库位名称"
            align="center"
            width="160"
          />
          <el-table-column
            prop="ownerName"
            label="货主名称"
            align="center"
            width="160"
          />
          <el-table-column
            prop="goodsName"
            label="货品名称"
            align="center"
            width="160"
          />
          <el-table-column
            prop="idNum"
            label="损益数量"
            align="center"
            width="160"
          />
          <el-table-column
            prop="idMoney"
            label="损益金额(元)"
            align="center"
            width="160"
          />
          <el-table-column
            prop="updateName"
            label="创建人"
            align="center"
            width="200"
          />
          <el-table-column
            prop="updateTime"
            label="创建时间"
            align="center"
            width="200"
          />
          <el-table-column
            prop="updateTime"
            label="损益来源"
            align="center"
            width="200"
          ><template v-slot="{ row }">{{
            getSource(row.idSource)
          }}</template></el-table-column>
          <el-table-column
            prop="taskCode"
            label="任务编号"
            align="center"
            width="200"
          />
          <el-table-column
            prop="status"
            label="损益单状态"
            align="center"
            width="200"
          ><template v-slot="{ row }">{{
            getStatus(row.status)
          }}</template></el-table-column>
          <el-table-column
            prop="createName"
            label="处理人"
            align="center"
            width="200"
          />
          <el-table-column
            sortable
            prop="createTime"
            label="处理时间"
            align="center"
            width="200"
          />
        </el-table>
        <PageTools
          :data="tableData"
          @handleSizeChange="handleSizeChangeFn"
          @handleCurrentChange="handleCurrentChangeFn"
        />
      </template>
    </el-row>
  </div>
</template>

<script>
import { getIncreaseDecreaseList, getIncreaseDecreaseSum } from '@/api/increaseDecrease'
import { getSource, getStatus, status } from '@/constant/increaseDecrease'
export default {
  data() {
    return {
      status,
      getSource,
      getStatus,
      isNowData: true,
      searchForm: {
        current: 1,
        size: 10,
        code: null,
        status: null,
        goodsName: null,
        ownerName: null
      },
      tableData: {},
      sum: 0
    }
  },
  async  created() {
    this.getIncreaseDecreaseList()
    const { data } = await getIncreaseDecreaseSum()
    this.sum = data.total
  },
  methods: {
    async getIncreaseDecreaseList() {
      const { data } = await getIncreaseDecreaseList(this.searchForm)
      this.isNowData = !data.records.length
      this.tableData = data
    },
    onSubmit() {
      this.searchForm.current = 1
      this.getIncreaseDecreaseList()
    },
    reset() {
      this.searchForm.code = null
      this.searchForm.status = null
      this.searchForm.goodsName = null
      this.searchForm.ownerName = null
      this.onSubmit()
    },
    handleSizeChangeFn(val) {
      this.searchForm.size = val
      this.searchForm.current = 1
      this.getOwnerList()
    },
    handleCurrentChangeFn(val) {
      this.searchForm.current = val
      this.getOwnerList()
    }
  }
}
</script>

<style lang="scss" scoped>
.warehouse {
  .table {
    padding: 0;
    margin-top: 20px;
    .add {
      padding: 20px 30px;
      border-bottom: 1px solid #f5efee;
    }
    .operate {
      color: #ffb200;
      cursor: pointer;
      &:hover {
        color: #ff8e00;
      }
      &.center {
        margin: 0 20px;
      }
    }
  }
  .infoTip {
    display: inline-block;
    height: 32px;
    line-height: 30px;
    background: #fff9eb;
    border: 1px solid #ffb200;
    padding: 0 25px;
    margin: 20px;
  }
}
</style>
